home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn RISC PD-CD 1
/
Acorn RISC PD-CD 1.iso
/
languages
/
perl
/
lib
/
termio
< prev
next >
Wrap
Text File
|
1990-06-20
|
1KB
|
67 lines
# Usage:
# $line = &termin();
# &termout($str1,$str2,...);
# $char = &getchar();
# &putchar($ch1,$ch2,...);
#
# Notes:
# 1. &termin() leaves a trailing newline.
# 2. &termin() gives undef on an error (eg escape)
# 3. &termout() does not automatically append a newline.
# 4. &termout() does not translate tabs.
# 5. &getchar() does not echo.
# 6. &putchar() translates "\n" or "\r" to a newline.
package termio;
sub main'termin {
local($buf) = ' ' x 255;
local($regs) = syscall("OS_ReadLine",$buf,255,32,127);
if ($regs) {
local($len) = unpack('x4 I',$regs);
$buf = substr($buf,0,$len) . "\n";
$buf;
}
else {
undef;
}
}
sub main'termout {
local ($_);
foreach (@_) {
s/\n/\r\n/g;
syscall("OS_Write0",$_);
}
}
sub main'getchar {
local ($ch) = syscall("OS_ReadC");
if ($ch) {
$ch = unpack('I',$ch);
$ch = pack('C',$ch);
$ch;
}
else {
undef;
}
}
sub main'putchar {
local($_);
foreach (@_) {
if ($_ eq "\n" || $_ eq "\r") {
syscall("OS_NewLine");
}
else {
$_ = ord($_);
syscall("OS_WriteC",$_);
}
}
}
1;